<template>
  <j-modal
    title="充值"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <a-spin :spinning="confirmLoading">
      <a-form-model ref="form" :model="model" :rules="validatorRules">
        <!-- <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="userId" label="用户id">
          <a-input placeholder="请输入用户id" v-model="model.userId" />
        </a-form-model-item> -->
        <a-form-model-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          prop="amount"
          label="充值他币"
        >
          <a-input-number
            v-model="model.amount"
            :parser="parseValue"
            :min="1"
            :max="99999"
            :step="1"
            style="width: 100%;"
            placeholder="请输入他币个数(最大为五位数)"
          />
        </a-form-model-item>
        <a-form-model-item
          label="支付方式"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          prop="paymentName"
        >
          <!-- <a-select v-model="model.paymentName" placeholder="请选择支付类型">
                <a-select-option value="后台支付" >后台支付</a-select-option>
              </a-select> -->

          <a-radio-group v-model="model.paymentName" >
            <a-radio value="后台支付">
              后台支付
            </a-radio>
          </a-radio-group>
        </a-form-model-item>
        <!-- <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="withdrawalAmount" label="提现金额">
          <a-input-number v-model="model.withdrawalAmount"/>
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="balance" label="余额">
          <a-input-number v-model="model.balance"/>
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="delFlag" label="删除状态(0-正常,1-已删除)">
          <a-input placeholder="请输入删除状态(0-正常,1-已删除)" v-model="model.delFlag" />
        </a-form-model-item>
		 -->
      </a-form-model>
    </a-spin>
  </j-modal>
</template>

<script>
import { getAction } from "@/api/manage";
import moment from "moment";

export default {
  name: "AssetModal",
  data() {
    return {
      title: "操作",
      visible: false,
      model: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },

      confirmLoading: false,
      validatorRules: {},
      url: {
        add: "/asset/asset/recharge",
        edit: "/asset/asset/recharge",
      },
      validatorRules: {
        amount: [{ required: true, message: "请充值他币(最大充值9999)" }],
        paymentName: [{ required: true, message: "请选择支付方式" }],
      },
    };
  },
  created() {},
  mounted() {
    this.model.paymentName = "后台支付"
  },
  methods: {
    //限制年龄小数点和负数
    parseValue(value) {
      // 如果输入值不是数字或者小数，则返回0
      if (isNaN(value) || value.indexOf(".") !== -1 || value < 0) {
        value.match(/^\d{0,5}/)[0];
        return 0;
      }
      return value;
    },
    add() {
      //初始化默认值
      this.edit({});
    },
    edit(record) {
      record["paymentName"] = "后台支付";
      this.model = Object.assign({}, record);
      this.visible = true;
    },
    close() {
      this.$emit("close");
      this.visible = false;
      this.$refs.form.clearValidate();
    },
    handleOk() {
      const that = this;
      // 触发表单验证
      this.$refs.form.validate((valid) => {
        if (valid) {
          that.confirmLoading = true;
          let httpurl = "";
          let method = "";
          if (!this.model.id) {
            httpurl += this.url.add;
            method = "post";
          } else {
            httpurl += this.url.edit;
            method = "post";
          }
          getAction(httpurl, this.model)
            .then((res) => {
              if (res.success) {
                that.$message.success(res.message);
                that.$emit("ok");
              } else {
                that.$message.warning(res.message);
              }
            })
            .finally(() => {
              that.confirmLoading = false;
              that.confirmLoading = false;
              that.close();
            });
        } else {
          return false;
        }
      });
    },
    handleCancel() {
      this.close();
    },
  },
};
</script>

<style lang="less" scoped></style>
